package org.abacus.platform.client.widget;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;

public class TextButton extends Text {
	private static final Object CONSTRAINTS = BorderLayout.EAST;

	final JButton button;

	final JPanel panel;

	public TextButton(String label) {
		super(label);
		button = new JButton();
		panel = new JPanel();
		init();
	}

	public JButton getButton() {
		return button;
	}

	public JPanel getPanel() {
		return panel;
	}

	private void init() {
		initPanel();
	}

	private void initButton() {
		String text = ">>";
		button.setText(text);
		Dimension preferredSize = new Dimension(30, FIELD_HEIGHT - 3);
		button.setPreferredSize(preferredSize);
		button.setFocusable(false);
		button.setMargin(new Insets(0, 0, 0, 0));
		button.setFont(new Font("宋体", 1, 8));
	}

	private void initField() {
		initButton();
		field.add(button, CONSTRAINTS);
		field.repaint();
		field.revalidate();
	}

	private void initPanel() {
		initField();
		panel.add(label);
		panel.add(field);
		panel.setBorder(BorderFactory.createLineBorder(new java.awt.Color(51, 255, 51)));
	}
}
